package com.hgd.security.evp.biz.rest;

import com.hgd.security.evp.biz.biz.EvpDictBiz;
import com.hgd.security.evp.biz.entity.EvpDict;
import com.hgd.security.evp.common.util.ObjectResultResponse;
import com.hgd.security.evp.common.util.TableResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("evpDict")
@Api(tags = "字典服务")
public class EvpDictController {

    @Autowired
    private EvpDictBiz evpDictBiz;

    @GetMapping("/list")
    @ApiOperation("分页获取列表")
    public TableResultResponse<EvpDict> getDictList(
        @RequestParam(value = "dictLabel",defaultValue = "") @ApiParam("字典名称") String dictLabel,
        @RequestParam(value = "page",defaultValue = "1") @ApiParam("当前页") Integer page,
        @RequestParam(value = "rows",defaultValue = "10") @ApiParam("页容量") Integer rows
    ){
        EvpDict evpDict=new EvpDict();
        evpDict.setDictLabel(dictLabel);

        return evpDictBiz.getDictList(evpDict,page,rows);
    }

    @GetMapping("/list/combobox")
    @ApiOperation("分页获取列表")
    public List<EvpDict> getDictListCombobox(
        @RequestParam(value = "dictLabel",defaultValue = "") @ApiParam("字典名称") String dictLabel
    ){
        EvpDict evpDict=new EvpDict();
        evpDict.setDictLabel(dictLabel);

        TableResultResponse<EvpDict> dictList = evpDictBiz.getDictList(evpDict, 1, Integer.MAX_VALUE);

        return dictList.getRows();
    }

    @PostMapping("/instance")
    @ApiOperation("添加单个对象")
    public ObjectResultResponse<Void> addDict(@RequestBody @ApiParam("待添加实例") EvpDict evpDict){
        return evpDictBiz.addDict(evpDict);
    }

    @PutMapping("/instance")
    @ApiOperation("更新单个对象")
    public ObjectResultResponse<Void> updateDict(@RequestBody @ApiParam("待更新实例") EvpDict evpDict){
        return evpDictBiz.updateDict(evpDict);
    }

    @DeleteMapping("/instance/{id}")
    @ApiOperation("删除单个对象")
    public ObjectResultResponse<Void> deleteDict(@PathVariable("id") Integer id){
        return evpDictBiz.deleteDict(id);
    }
}